// 
//  main.vala
//  
//  Author:
//       Alexandre Rosenfeld <alexandre.rosenfeld@gmail.com>
//  
//  Copyright (c) 2011 Alexandre Rosenfeld
// 
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
// 
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
// 
//  You should have received a copy of the GNU Lesser General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.

//[DBus (name = "org.gnome.UPnP.MediaObject2")]
public interface MediaObject : Object {
	public abstract ObjectPath Parent { get; set; }
	public abstract string Type { get; set; }
	public abstract string Path { get; set; }
	public abstract string DisplayName { get; set; }
}

[DBus (name = "org.gnome.UPnP.MediaContainer2", name = "org.gnome.UPnP.MediaObject2")]
public class MediaContainer : Object {
	private uint _child;
	private MediaContainer _parent;

	public MediaContainer(MediaContainer? parent) {
		this.parent = parent;
	}
	
	private MediaContainer parent {
		get {
			return this._parent;
		}
		set {
			this._parent = value;
			if (this._parent == null)
				this.Parent = new ObjectPath("/org/gnome/UPnP/MediaServer2/AirVideo");
			else
				this.Parent = new ObjectPath("/org/gnome/UPnP/MediaServer2/AirVideo");
		}
	}

	public ObjectPath Parent { get; private set; }
	public string Type { get; set; default = ""; }
	public string Path { get; set; default = ""; }
	public string DisplayName { get; set; default = ""; }

	public uint ChildCount { 
		get {
			return this._child;
		}
		set {
			this._child = value;
		} 
	}

	public signal void Updated ();
}

void on_bus_aquired (DBusConnection conn) {
	try {
		conn.register_object ("/org/gnome/UPnP/MediaServer2/AirVideo", new MediaContainer (null));
	} catch (IOError e) {
		stderr.printf ("Could not register service\n");
	}
}

void main () {
	Bus.own_name (BusType.SESSION, "org.gnome.UPnP.MediaServer2.AirVideo", BusNameOwnerFlags.NONE,
	              on_bus_aquired,
	              () => {},
	              () => stderr.printf ("Could not aquire name\n"));
	
	new MainLoop ().run ();
}